package com.sanpu.kxe.business.trade.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.business.trade.bean.SupportBankOutput;

import java.util.ArrayList;
import java.util.List;

/**
 * Description：支持的银行
 * Created by 薛勇军 on 2019/3/7.
 */

public class SupportBankAdapter extends BaseAdapter {

    private List<SupportBankOutput> listData = new ArrayList<>();

    private Context context;

    public SupportBankAdapter(List<SupportBankOutput> datas, Context context) {
        this.listData = datas;
        this.context = context;
    }

    /**
     * 刷新数据列表
     */
    public void setNotifyData(List<SupportBankOutput> retDatBeanList) {
        listData.clear();
        if (retDatBeanList != null) {
            listData.addAll(retDatBeanList);
        }
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (listData == null)
            return 0;
        return listData.size();
    }

    @Override
    public SupportBankOutput getItem(int position) {
        if (listData == null)
            return null;
        return listData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_support_banks, null);
        }
        LinearLayout itemParentLl = (LinearLayout) convertView.findViewById(R.id.itemParentLl);
        TextView bankNameTv = (TextView) convertView.findViewById(R.id.bankNameTv);
        TextView bankContentTv = (TextView) convertView.findViewById(R.id.bankContentTv);

        SupportBankOutput retDatBean = getItem(position);
        if (retDatBean != null) {
            if (retDatBean.getBankName() != null) {
                bankNameTv.setText(retDatBean.getBankName());
            }
            bankContentTv.setText(retDatBean.getMinTradeAmount()+"-"+retDatBean.getMaxTradeAmount());
            if (position%2 == 1) {
                itemParentLl.setBackgroundColor(ContextCompat.getColor(context, R.color.c_f3f3f3));
            } else {
                itemParentLl.setBackgroundColor(ContextCompat.getColor(context, R.color.c_e8e7e7));
            }
        }
        return convertView;
    }
}
